<template>
  <Dialog v-model="dialogVisible" :title="dialogTitle">
    <ContentWrap>
      <el-form :model="queryParams" ref="queryFormRef" label-width="auto" :inline="true">
        <el-form-item label="姓名" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入姓名"
            :clearable="true"
            @keyup.enter="getPage"
          />
        </el-form-item>
        <el-form-item>
          <el-button @click="handleClickSearch">
            <Icon icon="ep:search" />
            搜索
          </el-button>
          <el-button @click="handleClickReset">
            <Icon icon="ep:refresh" />
            重置
          </el-button>
        </el-form-item>
      </el-form>
      <Table
        :columns="columns"
        :page-param="queryParams"
        :adaptive="true"
        :page-data="queryData"
        save-key="HealthMedicinePlanSelect"
        @page-change="getPage"
        @row-dblclick="handleDblclick"
      />
    </ContentWrap>
  </Dialog>
</template>
<script setup name="HealthMedicinePlanSelect" lang="ts">
import * as HealthMedicinePlanApi from '@/api/health/medicinePlan'
const emit = defineEmits(['rowDblclick'])
const dialogTitle = ref('')
const dialogVisible = ref(false)
const queryFormRef = ref()
const queryParams = ref({
  name: undefined
})
const queryData = ref()
const columns = [
  {
    label: '姓名',
    prop: 'elder.name'
  },
  {
    label: '用药种类数',
    prop: 'medicineTypeNumber'
  },
  {
    label: '创建时间',
    prop: 'createTime'
  }
]
/** 打开弹窗 */
const open = () => {
  dialogVisible.value = true
  getPage()
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 搜索按钮操作 */
const handleClickSearch = () => {}

/** 重置按钮操作 */
const handleClickReset = () => {
  queryFormRef.value?.resetFields()
  handleClickSearch()
}

/** 处理响应事件  */
const getPage = async () => {
  queryData.value = await HealthMedicinePlanApi.pageQuery(queryParams.value)
}

const handleDblclick = (row) => {
  emit('rowDblclick', row)
  close()
}

/** 关闭弹窗 */
const close = async () => {
  dialogVisible.value = false
}
</script>
